import Vue from "vue";

import "normalize.css/normalize.css"; // A modern alternative to CSS resets

import ElementUI from "element-ui";
import "element-ui/lib/theme-chalk/index.css";
import locale from "element-ui/lib/locale/lang/en"; // lang i18n

import "@/styles/index.scss"; // global css

import App from "./App";
import store from "./store";
import router from "./router";

import checkPermission from "@/mixin/checkPermission";

import "@/icons"; // icon
import "@/permission"; // permission control

import Component from "@/componets";
import i18n from "@/lang";

//  *代表所有的内容（按需导出和默认导出的所有内容）
// 从 @/directives 文件中导入所有内容， 并重命名为 directives
import * as directives from "@/directives"; //directives = {imageerror：{内容}}
import * as filters from "@/filters"; // 过滤器
// 全局注册过滤器
Object.keys(filters).forEach((key) => {
  Vue.filter(key, filters[key]);
});
// 获取 对象中所有的属性名 并 返回值为一个数组
var arr = Object.keys(directives); // ['imageerror']
// 遍历 arr 数组
arr.forEach((key) => {
  // 注册自定义指令 directives[key] = directives['imageerror'] 取出 imageerror 内的内容
  Vue.directive(key, directives[key]);
});

Vue.use(Component); // 全局注册通用栏组件对象
Vue.mixin(checkPermission);

/**
 * If you don't want to use mock-server
 * you want to use MockJs for mock api
 * you can execute: mockXHR()
 *
 * Currently MockJs will be used in the production environment,
 * please remove it before going online ! ! !
 */
// if (process.env.NODE_ENV === 'production') {
//   const { mockXHR } = require('../mock')
//   mockXHR()
// }

// set ElementUI lang to EN
// Vue.use(ElementUI, { locale });
Vue.use(ElementUI, { i18n: (key, value) => i18n.t(key, value) });
// 如果想要中文版 element-ui，按如下方式声明
// Vue.use(ElementUI);

Vue.config.productionTip = false;

new Vue({
  el: "#app",
  router,
  store,
  i18n,
  render: (h) => h(App),
});
